import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userName: 'hello'
  },
  getters: {
    fullName (state) {
      return state.userName + '---vuex...'
    }
  },
  mutations: {
    CHANGE_NAME (state, payload) {
      this.state.userName = payload
    }
  },
  actions: {
    changeName ({ commit }, payload) {
      setTimeout(() => {
        commit('CHANGE_NAME', '2秒后修改 userName')
      }, 2000)
    }
  },
  modules: {
  }
})
